package tank.cor;

import tank.Bullet;
import tank.Explode;
import tank.GameModel;
import tank.GameObject;
import tank.Tank;

public class BullteTankCollider implements Collider {

	@Override
	public boolean collide(GameObject o1, GameObject o2) {
		if(o1 instanceof Bullet && o2 instanceof Tank) {
			Bullet bullet = (Bullet)o1;
			Tank tank = (Tank)o2;
			if(bullet.getGroup() == tank.getGroup()) return false;
			if(bullet.getRect().intersects(tank.getRect())) {
				tank.die();
				bullet.die();
				int eX = tank.getX() + Tank.WIDTH/2 - Explode.WIDTH/2;
				int eY = tank.getY() + Tank.HEIGHT/2 - Explode.HEIGHT/2;
				new Explode(eX, eY);
				return true;
			}
		}else if(o2 instanceof Bullet && o1 instanceof Tank){
			return collide(o2, o1);
		}
		return false;
	}

}
